package com.jiajia.study.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiajia.common.utils.PageUtils;
import com.jiajia.common.utils.Query;
import com.jiajia.study.product.dao.AttrAttrgroupRelationDao;
import com.jiajia.study.product.entity.AttrAttrgroupRelationEntity;
import com.jiajia.study.product.entity.AttrEntity;
import com.jiajia.study.product.service.AttrAttrgroupRelationService;
import feign.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("attrAttrgroupRelationService")
public class AttrAttrgroupRelationServiceImpl extends ServiceImpl<AttrAttrgroupRelationDao, AttrAttrgroupRelationEntity> implements AttrAttrgroupRelationService {

    @Autowired
    AttrAttrgroupRelationDao attrAttrgroupRelationDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<AttrAttrgroupRelationEntity> page = this.page(
                new Query<AttrAttrgroupRelationEntity>().getPage(params),
                new QueryWrapper<AttrAttrgroupRelationEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<AttrAttrgroupRelationEntity> getByAttrId(Long attrId) {

        QueryWrapper<AttrAttrgroupRelationEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("attr_id",attrId);
        return this.list(queryWrapper);
    }

    @Override
    public void deleteBatchRelation(List<AttrAttrgroupRelationEntity> collect) {
        attrAttrgroupRelationDao.deleteBatch(collect);
    }

    @Override
    public List<AttrAttrgroupRelationEntity> getByAttrGroupId(Long attrGroupId) {

        QueryWrapper<AttrAttrgroupRelationEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("attr_group_id",attrGroupId);
        return this.list(queryWrapper);
    }

}
